<@ui.html>
<div class="container">
${rendered}
</div>
<script>
    function _on_preference_submit(dg) {
        var valid = true;
        if (window.onSubmit) {
            valid = onSubmit();
        }
        if (valid) {
            var args = [];
            if (window.getPreferences) {
                args = getPreferences() || [];
            } else {
                var tmp = {};
                $($("form").serializeArray()).each(function () {
                    var ary = tmp[this.name];
                    if (!ary) {
                        ary = [];
                        tmp[this.name] = ary;
                    }
                    ary.push(this.value);
                });
                for (v in tmp) {
                    args.push({
                        name: v,
                        value: tmp[v].join(",")
                    })
                }
            }
            return ['savePreference', args];
        } else {
            return false;
        }
    }
</script>
</@ui.html>